// pages/detail/detail.js
import { shareOptions } from "../../utils/access";
import request from "../../utils/request";
const api = require("../../config/api");
const wxParse = require("../../utils/wxParse/wxParse.js");
import { getStorage } from "../../utils/utils"

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		orderNo: "",
		orderInfo:{}, //订单信息
		recommendList:[] //猜你喜欢数据
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		wx.setNavigationBarColor({
			frontColor: "#000000",
			backgroundColor: "#f5f5f5",
		});

		this.setData({
			orderNo: options.orderNo,
		},()=>{
			this.getDetail(options.orderNo);
		});
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {},
	handleReturnHome() {
		wx.reLaunch({
			url: "/pages/idleHome/idleHome",
		});
	},
	handleReturnOrder() {
		let { orderNo } = this.data;
		wx.reLaunch({
			url: "/pages/idleOrderDetail/idleOrderDetail?orderNo=" + orderNo,
		});
	},
	async getDetail(orderNo) {
		const res = await request.get(api.getIdleOrderDetail, { orderNo });
		if (res.httpStatus === 200) {
			this.setData({
				orderInfo: res.data || {},
			})
      this.getGoodsRecommend() 
		}
	},
	/**
	 * 获取猜你喜欢数据
	 */
	async getGoodsRecommend(){
		let communityId= getStorage('communityId')
		let goodsClassifyId= this.data.orderInfo.goodsClassifyId
		const res= await request.get(api.recommendGoods, { 
			communityId,
      goodsClassifyId,
		}, { loading: false })
		this.setData({
			recommendList: res?.data || []
		})
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this.getGoodsRecommend()
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {},

	// 用户点击右上角分享
	onShareAppMessage(e) {
		return shareOptions('default', e)
	},
});
